package logic

import (
	"box-mart-api/boxrpc/boxrpc"
	"box-mart-api/boxrpc/internal/svc"
	"box-mart-api/models/mysql"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type BoxListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBoxListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BoxListLogic {
	return &BoxListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 列表
func (l *BoxListLogic) BoxList(in *boxrpc.BoxListRequest) (*boxrpc.BoxListResponse, error) {
	// todo: add your logic here and delete this line
	var box mysql.Box

	mysql.BoxList(mysql.DB, in)
	//if err != nil {
	//	return nil, err
	//}
	var list []*boxrpc.BoxList
	for _, data := range list {
		lists := boxrpc.BoxList{
			BoxId:    data.BoxId,
			BoxTitle: data.BoxTitle,
			BoxName:  data.BoxName,
			BoxPrice: data.BoxPrice,
			BoxType:  data.BoxType,
		}
		list = append(list, &lists)
	}
	mysql.DB.Find(&box)
	return &boxrpc.BoxListResponse{
		List: list,
	}, nil
}
